package com.game.data.dao.example.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import com.game.data.dao.example.PersonDAOCustom;
import com.game.model.example.Person;
/**
 * 自定义操作示例
 * http://yangjizhong.iteye.com/blog/1206901
 * @author Quake
 *
 */
public class PersonDAOImpl implements PersonDAOCustom {
	
	@Autowired
	private MongoTemplate mongoTemplate;
	@Override
	public void updateByDaily() {
		//Query
		Query query = new Query();
		//Update
		Update update = new Update().set("dailyCount", 0);
//		update.inc("dailyCount", 100);
		mongoTemplate.updateMulti(query, update, Person.class);
	}
	@Override
	public List<Person> customFind(String firstName) {
		Query query = new Query(Criteria.where("firstName").is(firstName));
		return mongoTemplate.find(query, Person.class);
	}

}
